
; ==========================================================================================
;
; main features:
;
;   - marked code:
;       to ease extensibility, changeability and reusability.
;       to make parallel programming possible-
;           "parallel" implies easy-to-use extensibily process-
;           data structure or algorithm might be described in more than one place of code
;           when this is applicable (i.e. orthogonal programming).
;
;   - region inference:
;       makes resource management transparent from programmer without demanding
;       GC overhead.
;
;
;   - possibility to connect to shared marked code repositories
;       to achieve better code reusability
;
;   - control version system 
ТРБ : Некоторое время назад Линус Торвальдс сказал, что он на самом деле ничего не имел против интеграции технологии DRM (Digital Rights Management, система управления правами на цифровую информацию) в GNU/Linux, и предположил, что GPL этого не запрещает.driver: mantains
;
; ==========================================================================================



; introducing forward declarations
(forwards
  (mark asm-function)

  (mark push-pop-instruction)
  ; mark inheritance sample
  (mark push-instruction push-pop-instruction)
  (mark pop-instruction push-pop-instruction)

  (type Register)
  (type Immediate)

  (func emit (Byte))
  (func emit (Immediate))
  (func (Byte code-of) Register)
  (func is-int8 Immediate)
  (func as-byte Immediate)
  )

; introducing constraints
(constraints
  (is (return-type code-of) Byte)
  )


; introducing functions that related to generating assembly
(func push ((const Register r))
      (mark asm-function
            (emit (bit-or 0x50 (code-of r)))
            ))


(func push ((const Immediate imm))
      (mark asm-function
            (if (is-int8 imm)
              (scope
                (emit 0x6a)
                (emit (as-byte imm)))
              (scope
                (emit 0x68)
                (emit imm)
                ))))

; other way of doung so is to define macro that encapsulates process of adding asm-function mark:
(macro asm-func (func-name arg-list (rest body))
       (scope
         (put-list 'func func-name arg-list
                   (put-list 'mark 'asm-function body))))


(asm-func mov ((Register dest) (Int32 imm32))
          (emit (bit-or 0xB8 (code-of dst)))
          (emit imm32)
          )





; all the functions above have mark (asm-function), so all these functions must be bound
; to certain context

(type Assembler)

(func asm-function-scope-controller ((Assembler asm) inferior-sequence)
      (grow-buffer-if-needed asm)
      (let ((space-before (avail-space asm)))
        (implement inferior-sequence)
        (let ((bytes-generated (- (avail-space asm) space-before)))
          (assert (< bytes-generated (gap asm)))
          )))

(with-mark asm-function
           (set-holder-context-type Assembler)
           (set-scope-controller asm-function-scope-controller)
           )

; set first argument of the function emit as Assembler
(within-mark asm-function
             (prepend-function-argument-to
               emit ; function name
               context ; Assembler argument
               ))

(func emit ((Assembler asm) (Byte byte))
      ; do this and that
      )




